< previous page page_405 next page >

Page 405
transformations of the grid. The image in the upper right was produced with this transformation.
When you have a transformation stored in a matrix, you can pass the matrix into a graphical object's Transform subroutine. The Transform subroutine can then apply the matrix to the points that make up the object.
Because you cannot store shape-distorting transformations in matrices, this strategy does not work for them. What you really need to do is pass a shape-distorting function into one of the graphical object's routines. Then that routine can use the function to transform the points making up the object. While you cannot pass a function into a Visual Basic subroutine, you can do something almost as good: You can pass an object.
Create a class to represent the shape-distorting transformation. If you like, you can give the class variables to make the transformation more general. The previous example uses the values Amplitude and Period to modify the basic transformation.
Next, give the class a Transform subroutine. This routine takes as parameters the coordinates of a point and applies a shape-distorting transformation to them. The following code shows the complete definition of the TransWave transformation class. The interface class Transformation defines the single method Transform, so this routine is called Transformation_Transform in the TransWave class that implements it. A program can treat this class and others that implement the Transformation class as Transformation objects.
e10a6a0a59f035e870d90cca05b85fce.gif
Option Explicit
' A wavy transformation.

Implements Transformation

' Transformation parameters.
Public Amplitude As Single
Public Period As Single

' Transform the point (X, Y).
Private Sub Transformation_Transform(X As Single, Y As Single)
0405-01.jpg
Figure 12.21
Program RotRect uses the Transform
subroutine to rotate rectangles.

 
< previous page page_405 next page >